﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeastSquareMethod.Models
{
    internal class DataGet
    {
        /// <summary>
        /// 工具类，用于从txt文件获取数据
        /// </summary>
        /// <param name="args"></param>
        public static void Get(List<string> x,List<string> y)
        {
            //打开txt文件
            StreamReader sr = new StreamReader
                ("D:\\CSharpHomework\\csharp-homework\\LeastSquareMethod\\YearandGDP.txt");
            //另一种方法(System.IO.File.OpenRead("D:\\CSharpHomework\\csharp-homework\\LeastSquareMethod\\YearandGDP.txt"))
            //依次读取数据
            for (int i = 0; i < 2; i++)
            {
                string line = sr.ReadLine();
                //以空格为分隔符
                var arrline = line.Split(" ");
                //第一行为year
                if (i == 0)
                    for (int j = 0; j < arrline.Length; j++)
                    {
                        x.Add(arrline[j]);
                    }
                //第二行为gdp
                else
                    for (int k = 0; k < arrline.Length; k++)
                    {
                        y.Add(arrline[k]);
                    }
            }
        }
    }
}
